#!/user/bin/env python
# -*- coding: utf-8 -*-
''' 
Author: Sjy
LastEditTime: 2024-08-30 10:30:45
Description: 警告提示对话框封装组件
'''

__all__= []


from PyQt5 import QtWidgets


def warning(text:str="", btnTitle:str="关闭", parent=None):
    messageBox = QtWidgets.QMessageBox(parent)
    # messageBox.setStyleSheet("QLabel{"
    #                   "min-width: 50px;"
    #                   "text-align:right;"
    #                   "min-height: 300px; "
    #                   "font-size:14px;"
    #                   "}");
    messageBox.setWindowTitle('警告')
    messageBox.setText(f"{text or ''}")
    messageBox.setIcon(QtWidgets.QMessageBox.Warning)
    messageBox.setStandardButtons(QtWidgets.QMessageBox.Cancel)
    buttonN = messageBox.button(QtWidgets.QMessageBox.Cancel)
    buttonN.setText(btnTitle)
    messageBox.exec_()


def success(text:str="", btnTitle:str="关闭", parent=None):
    messageBox = QtWidgets.QMessageBox(parent)
    messageBox.setWindowTitle('提示')
    messageBox.setText(f"{text or ''}")
    messageBox.setIcon(QtWidgets.QMessageBox.Information)
    messageBox.setStandardButtons(QtWidgets.QMessageBox.Cancel)
    buttonN = messageBox.button(QtWidgets.QMessageBox.Cancel)
    buttonN.setText(btnTitle)
    messageBox.exec_()


def confirm(text:str="", parent=None):
    messageBox = QtWidgets.QMessageBox(parent)
    messageBox.setWindowTitle('确认')
    messageBox.setText(f"{text or ''}")
    messageBox.setIcon(QtWidgets.QMessageBox.Question)
    messageBox.setStandardButtons(QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel)
    buttonY = messageBox.button(QtWidgets.QMessageBox.Ok)
    buttonY.setText('是')
    buttonN = messageBox.button(QtWidgets.QMessageBox.Cancel)
    buttonN.setText('否')
    reply = messageBox.exec()
    if reply == QtWidgets.QMessageBox.Ok:
        return True
    else:
        return False
    

def custom_warning(title:str="", msg:str="", show=False, parent=None) -> QtWidgets.QMessageBox:
    # 自定义警告对话框
    messageBox = QtWidgets.QMessageBox(parent)
    messageBox.setWindowTitle(title)
    messageBox.setText(msg)
    messageBox.setIcon(QtWidgets.QMessageBox.Warning)
    if show:
        messageBox.exec_()
    return messageBox


def select(title, label:str="", options:dict={}, parent=None):
    # 增加选择文本的通用对话框
    item, ok = QtWidgets.QInputDialog.getItem(parent, '选择', '测量数据类型:', options, 0, False)
    if ok:
        return item
    

    

